#
# @lc app=leetcode.cn id=720 lang=python3
#
# [720] 词典中最长的单词
#

# @lc code=start
class Solution:
    def longestWord(self, words: List[str]) -> str:
        preifx = set([''])
        words = sorted(words, key=len)
        for word in words:
            if word[:-1] in preifx:
                preifx.add(word)
        return max(sorted(preifx), key=len)
# @lc code=end
